package com.timss.opmm.service.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.timss.opmm.bean.Rules;
import com.timss.opmm.dao.RulesMapper;
import com.timss.opmm.service.RulesService;
import com.yudean.itc.dto.Page;

/**
 * @title: 值别service
 * @description: {desc}
 * @company: gdyd
 * @className: RulesServiceImpl.java
 * @author: fengzt
 * @createDate: 2014年6月4日
 * @updateUser: fengzt
 * @version: 1.0
 */
@Service("rulesService")
public class RulesServiceImpl implements RulesService {

    @Autowired
    private RulesMapper rulesMapper;

    public RulesMapper getRulesMapper() {
        return rulesMapper;
    }

    public void setRulesMapper(RulesMapper rulesMapper) {

        this.rulesMapper = rulesMapper;
    }

    /**
     * @description:查询结果中返回主键id的方法
     * @author: fengzt
     * @createDate: 2014年6月4日
     * @param Rules 其中id为自增，不需要设置
     * @return:Rules
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public Rules insertRules(Rules rules) {

        rulesMapper.insertRules( rules );
        return rules;
    }

    /**
     * @description:更新值别表
     * @author: fengzt
     * @createDate: 2014年6月4日
     * @param Rules:
     * @return int
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public int updateRules(Rules rules) {
        return rulesMapper.updateRules( rules );
    }

    /**
     * @description:通过Id拿到值别表
     * @author: fengzt
     * @createDate: 2014年6月4日
     * @param id
     * @return:Rules
     */
    public Rules getRulesById(int id) {

        return rulesMapper.getRulesById( id );
    }

    /**
     * @description:通过ID 删除 Rules
     * @author: fengzt
     * @createDate: 2014年6月4日
     * @param id:
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public int deleteRulesById(int id) {

        return rulesMapper.deleteRulesById( id );
    }

    /**
     * @description:更新Rules
     * @author: fengzt
     * @createDate: 2014年6月4日
     * @param RulesMap:
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public void updateRulesByMap(HashMap<?, ?> rulesMap) {

    }

    /**
     * @description:批量插入
     * @author: fengzt
     * @createDate: 2014年6月4日
     * @param list:
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public void batchInsertRules(List<Rules> list) {

    }

    /**
     * @description:Rules 分页
     * @author: fengzt
     * @createDate: 2014年6月4日
     * @param page
     * @return:
     */
    public List<Rules> getRulesByPage(Page<HashMap<?, ?>> page) {
        page.setSortKey( "id" );
        page.setSortOrder( "asc" );
        
        return rulesMapper.getRulesByPage( page );
    }

    /**
     * @description:Rules 分页 (返回hashmap)
     * @author: fengzt
     * @createDate: 2014年6月4日
     * @param page
     * @return: List<HashMap<?, ?>>
     */
    public List<HashMap<?, ?>> getRulesMapByPage(Page<HashMap<?, ?>> page) {
        return null;
    }

    /**
     * @description:拿出所有值别Rules
     * @author: fengzt
     * @createDate: 2014年6月4日
     * @return:
     */
    public List<Rules> getAllRules() {
        return rulesMapper.getAllRules();
    }

    /**
     * @description:通过hashmap 拿到List
     * @author: fengzt
     * @createDate: 2014年6月4日
     * @param map
     * @return:List<Rules>
     */
    public List<Rules> getRulesByMap(HashMap<?, ?> map) {
        return null;
    }

    /**
     * @description:值别列表 高级搜索
     * @author: fengzt
     * @createDate: 2014年6月4日
     * @param Rules 查询form vo
     * @param rows 一页有多少条
     * @param page 第几页
     * @return:List<Rules>
     */
    public List<Rules> getRulesBySearch(HashMap<String, Object> map, Page<HashMap<?, ?>> page) {
        page.setParameter( "id", map.get( "id" ) );
        page.setParameter( "num", map.get( "num" ) );
        page.setParameter( "name", map.get( "name" ) );

        page.setParameter( "siteId", map.get( "siteId" ) );
        page.setParameter( "available", map.get( "available" ) );
        page.setParameter( "changeLimit", map.get( "changeLimit" ) );
        page.setParameter( "pollSequence", map.get( "pollSequence" ) );
        
        page.setSortKey( "id" );
        page.setSortOrder( "asc" );

        List<Rules> rulesList = rulesMapper.getRulesBySearch( page );
        return rulesList;
    }

}
